import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

class ImagePickerPage extends StatefulWidget {
  const ImagePickerPage({super.key});

  @override
  State<ImagePickerPage> createState() => _ImagePickerPageState();
}

class _ImagePickerPageState extends State<ImagePickerPage> {

  final ImagePicker _picker = ImagePicker();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Flutter App"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(onPressed: () async {
              // Pick an image.
              final XFile? image = await _picker.pickImage(source: ImageSource.gallery);

              /*// Pick a video.
              final XFile? galleryVideo = await _picker.pickVideo(source: ImageSource.gallery);
              // Capture a video.
              final XFile? cameraVideo = await _picker.pickVideo(source: ImageSource.camera);
              // Pick multiple images.
              final List<XFile> images = await _picker.pickMultiImage();
              // Pick singe image or video.
              final XFile? media = await _picker.pickMedia();
              // Pick multiple images and videos.
              final List<XFile> medias = await _picker.pickMultipleMedia();*/
            }, child: const Text("调用相机")),
            ElevatedButton(onPressed: () async {
              // Capture a photo.
              final XFile? photo = await _picker.pickImage(source: ImageSource.camera);
            }, child: const Text("打开相册")),
          ],
        ),
      )
    );
  }
}
